/**
 * Copyright (c) 2012, Camelot and/or its affiliates. All rights reserved.
 * Camelot PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.camelot.ccr.global.web.interceptor;

import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.camelot.ccr.system.persistence.User;
import org.apache.log4j.Logger;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.camelot.ccr.global.util.Utility;

/**
 * <pre>
 * 处理全局业务日志信息拦截器
 * </pre>
 * @author Liu Jun
 * @version V0.1, 2014-2-10 上午11:04:09
 */
public class SessionInterceptor extends HandlerInterceptorAdapter {

	private Logger log = Logger.getLogger(SessionInterceptor.class);
	
	/**
	 * 处理请求参数记录日志
	 */
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		try {
            User user = (User)request.getSession().getAttribute("user");
            if(Utility.isNull(user)){
                response.sendRedirect(request.getContextPath()+"/login.jsp");
                return false;
            }
			return super.preHandle(request, response, handler);
		} catch (Exception e) {
			e.printStackTrace();
			log.error("系统异常！",e);
			throw new Exception(e);
		}
	}
}
